<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>抖音小视频</title>
    <style>
        .video-container{
            height: 500px;
        }
        video{
            height: 100%;
        }
    </style>
</head>
<body>
    <button>来个好玩的</button>
    <button>下去吧</button>
    <hr>

    <div id="root"></div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class Video extends React.Component {
            state = {
                src: 'http://api.xiaohigh.com:8090/video/random'
            }
            //3. 渲染
            render(){
                console.log('3-渲染中, 挂载中.. - render');
                return <div className="video-container" onClick={this.change}>
                        <video controls={true} autoPlay src={this.state.src}></video>
                    </div>
            }

            change = () => {
                this.setState({
                    src: 'http://api.xiaohigh.com:8090/video/random?t='+Date.now()
                })
            }

            //1. 构造方法
            constructor(props) {
                super(props);
                console.log('1-构造方法执行 - constructor');
            }

            //2. 将要挂载
            componentWillMount(){
                console.log('2-组件将要挂载 - componentWillMount');
            }

            //4. 完成挂载 did do 过去式, 表示完成
            componentDidMount(){
                console.log('4-组件完成挂载 - componentDidMount');
            }
            

        }



        //获取按钮
        let btns = document.querySelectorAll('button');

        btns[0].onclick = function(){
            ReactDOM.render(<Video />, document.querySelector("#root"));
        }

        btns[1].onclick = function(){
            ReactDOM.unmountComponentAtNode(document.querySelector('#root'));
        }

    </script>
</body>
</html>